package com.ks.core.framework.cpsupload.demos.orderpayinvoice.orderhandler;

import com.ks.core.framework.cpsupload.demos.orderpayinvoice.constant.InvoiceType;
import com.ks.core.framework.cpsupload.demos.orderpayinvoice.event.InvoiceCallbackEvent;

// 发票服务
class InvoiceService {
    // 生成发票
    public static void generateInvoice(Order order, InvoiceType type) {
        // 调用开票系统API
        System.out.println("生成发票: 订单=" + order.getOrderId() + 
                          ", 类型=" + type);
        if (type == InvoiceType.BLUE) {
            order.setInvoiceIssued(true);
        }
    }
    
    // 生成部分红冲发票
    public static void generatePartialRedInvoice(Order order) {
        System.out.println("生成部分红冲发票: 订单=" + order.getOrderId());
    }
    
    // 处理发票回调
    public void handleInvoiceCallback(InvoiceCallbackEvent event) {
        Order order = loadOrder(event.getOrderId());
        
        if (event.getStatus() == InvoiceCallbackEvent.InvoiceStatus.SUCCESS) {
            if (event.getInvoiceType() == InvoiceType.BLUE) {
                // 保存蓝票文件
                saveBlueInvoice(order, event.getFileUrl());
            } else {
                // 保存红票文件
                saveRedInvoice(order, event.getFileUrl());
            }
        }
    }
    
    // 其他辅助方法...
}